#!/bin/bash
#
# gnome-power-control
# 对计算机进行挂起和休眠，适用于非 gnome/kde 桌面环境。
# No sudo, no root, no fuss!
#
# usage:
#   gnome-power-control suspend
#   gnome-power-control hibernate
#   gnome-power-control reboot
#   gnome-power-control shutdown
#
# ubuntu 11.10

case $1 in
suspend)
echo Suspending
    dbus-send --print-reply \
        --system \
        --dest=org.freedesktop.UPower \
        /org/freedesktop/UPower \
        org.freedesktop.UPower.Suspend
;;
hibernate)
echo Hibernating
    dbus-send --print-reply \
        --system \
        --dest=org.freedesktop.UPower \
        /org/freedesktop/UPower \
        org.freedesktop.UPower.Hibernate
;;
reboot)
echo Rebooting
    dbus-send --system \
	--print-reply \
	--dest=org.freedesktop.ConsoleKit \
	/org/freedesktop/ConsoleKit/Manager \
	org.freedesktop.ConsoleKit.Manager.Restart
;;
shutdown)    
echo Shutdowning
    dbus-send --system \
	--print-reply \
	--dest=org.freedesktop.ConsoleKit \
	/org/freedesktop/ConsoleKit/Manager \
	org.freedesktop.ConsoleKit.Manager.Stop
;;
*)
echo Not supported command: '"'$1'"'
echo Usage: $0 '<suspend|hibernate|reboot|shutdown>'
exit 1
;;
esac
